package com.gydz.gydzbaseframeworkboot.common.utils;

import com.gydz.gydzbaseframeworkboot.gsCenter.dao.*;
import com.gydz.gydzbaseframeworkboot.gsCenter.domain.*;
import com.gydz.gydzbaseframeworkboot.wgCenter.dao.*;
import com.gydz.gydzbaseframeworkboot.wsCenter.dao.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Component
@EnableScheduling
public class WgTask {


    @Autowired
    WgBscMapper bscMapper;

    @Autowired
    WsBscMapper wsBscMapper;

    @Autowired
    WgBtseMapper btseMapper;

    @Autowired
    WsBtseMapper wsBtseMapper;

    @Autowired
    WgBtsihoMapper btsihoMapper;

    @Autowired
    WsBtsihoMapper wsBtsihoMapper;

    @Autowired
    WgBtsMapper btsMapper;

    @Autowired
    WsBtsMapper wsBtsMapper;


    @Autowired
    WgBtsmMapper btsmMapper;

    @Autowired
    WsBtsmMapper wsBtsmMapper;

    @Autowired
    WgBtsohoiMapper btsohoiMapper;

    @Autowired
    WsBtsohoiMapper wsBtsohoiMapper;

    @Autowired
    WgBtsohonMapper btsohonMapper;

    @Autowired
    WsBtsohonMapper wsBtsohonMapper;

    @Autowired
    WgBtsohosMapper btsohosMapper;

    @Autowired
    WsBtsohosMapper wsBtsohosMapper;

    @Autowired
    WgCtrxMapper ctrxMapper;

    @Autowired
    WsCtrxMapper wsCtrxMapper;

    @Autowired
    WgFbtsmMapper fbtsmMapper;

    @Autowired
    WsFbtsmMapper wsFbtsmMapper;

    @Autowired
    WgGprsMapper gprsMapper;

    @Autowired
    WsGprsMapper wsGprsMapper;

    @Autowired
    WgTgtbtsMapper tgtbtsMapper;

    @Autowired
    WsTgtbtsMapper wsTgtbtsMapper;

    @Autowired
    WgTrxMapper trxMapper;

    @Autowired
    WsTrxMapper wsTrxMapper;

    @Autowired
    WgDpcMapper wgDpcMapper;

    @Autowired
    WsDpcMapper wsDpcMapper;








    //获取并插入前一小时bsc数据
    @Scheduled(cron = "0 */23 * * * ?")
      public void insertbsc() {
        Bsc bsc=new Bsc();
        bsc.setDate(getperviouscalender());
        bsc.setHour(getpervioushour());
        List<Bsc> list= bscMapper.selectBscList(bsc);
        for (Bsc b :list
           ) {
             int i=wsBscMapper.insertBsc(b);
             if (i>0){
                 System.out.println("武广bsc插入成功");
             }
        }
    }
     //获取并插入前一小时btse数据
     @Scheduled(cron = "0 */20 * * * ?")
    public void insertbtse() {
        Btse btse=new Btse();
        btse.setDate(getperviouscalender());
        btse.setHour(getpervioushour());
//         btse.setDate("2023-11-19");
//         btse.setHour(0l);
        List<Btse> list= btseMapper.selectBtseList(btse);
        for (Btse b :list
        ) {
            int i=wsBtseMapper.insertBtse(b);
            if (i>0){
                System.out.println("武广btse插入成功");
            }
        }
    }
//
//    //获取并插入前一小时btsiho数据
@Scheduled(cron = "0 0 */1 * * ?")
    public void insertbtsiho() {
        Btsiho btsiho=new Btsiho();
        btsiho.setDate(getperviouscalender());
        btsiho.setHour(getpervioushour());
//        btsiho.setDate("2023-11-22");
//        btsiho.setHour(getpervioushour());
        List<Btsiho> list= btsihoMapper.selectBtsihoList(btsiho);
        for (Btsiho b :list
        ) {
            int i=wsBtsihoMapper.insertBtsiho(b);
            if (i>0){
                System.out.println("武广btsiho插入成功");
            }
        }
    }

    //获取并插入前一小时bts数据
    @Scheduled(cron = "0 */28 * * * ?")
     public void insertbts() {
        Bts bts=new Bts();
        bts.setDate(getperviouscalender());
        bts.setHour(getpervioushour());
//        bts.setDate("2023-12-14");
//        bts.setHour(19L);
        List<Bts> list= btsMapper.selectBtsList(bts);
        for (Bts b :list
        ) {
            int i=wsBtsMapper.insertBts(b);
            if (i>0){
                System.out.println("武广bts插入成功");
            }
        }
    }
    //获取并插入前一小时btsm数据
    @Scheduled(cron = "0 0 */1 * * ?")
    public void insertbtsm() {
        Btsm btsm=new Btsm();
        btsm.setDate(getperviouscalender());
        btsm.setHour(getpervioushour());
        List<Btsm> list= btsmMapper.selectBtsmList(btsm);
        for (Btsm b :list
        ) {
            int i=wsBtsmMapper.insertBtsm(b);
            if (i>0){
                System.out.println("武广btsm插入成功");
            }
        }
    }
//
//    //获取并插入前一小时btsohoi数据
@Scheduled(cron = "0 */25 * * * ?")
    public void insertbtsohoi() {
        Btsohoi btsohoi=new Btsohoi();
        btsohoi.setDate(getperviouscalender());
        btsohoi.setHour(getpervioushour());
        List<Btsohoi> list= btsohoiMapper.selectBtsohoiList(btsohoi);
        for (Btsohoi b :list
        ) {
            int i=wsBtsohoiMapper.insertBtsohoi(b);
            if (i>0){
                System.out.println("武广btsohoi插入成功");
            }
        }
    }

    //获取并插入前一小时btsohon数据
    @Scheduled(cron = "0 */25 * * * ?")
    public void insertbtsohon() {
        Btsohon btsohon=new Btsohon();
        btsohon.setDate(getperviouscalender());
        btsohon.setHour(getpervioushour());
        List<Btsohon> list= btsohonMapper.selectBtsohonList(btsohon);
        for (Btsohon b :list
        ) {
            int i=wsBtsohonMapper.insertBtsohon(b);
            if (i>0){
                System.out.println("广深btsohon插入成功");
            }
        }
    }

    //获取并插入前一小时btsohos数据
    @Scheduled(cron = "0 */20 * * * ?")
    public void insertbtsohos() {
        Btsohos btsohos=new Btsohos();
        btsohos.setDate(getperviouscalender());
        btsohos.setHour(getpervioushour());
        List<Btsohos> list= btsohosMapper.selectBtsohosList(btsohos);
        for (Btsohos b :list
        ) {
            int i=wsBtsohosMapper.insertBtsohos(b);
            if (i>0){
                System.out.println("武广btsohos插入成功");
            }
        }
    }

    @Scheduled(cron = "0 */30 * * * ?")
    public void insertctrx() {
        System.out.println("开始执行武广ctrx数据汇合");
        Ctrx ctrx=new Ctrx();
        ctrx.setDate(getperviouscalender());
        ctrx.setHour(getpervioushour());
//        ctrx.setDate("2023-12-18");
//        ctrx.setHour(11L);
        List<Ctrx> list= ctrxMapper.selectCtrxList(ctrx);
        for (Ctrx b :list
        ) {
            int i=wsCtrxMapper.insertCtrx(b);
            if (i>0){
                System.out.println("武广Ctrx插入成功");
            }
        }
    }

    @Scheduled(cron = "0 */20 * * * ?")
    public void insertfbtsm() {
        Fbtsm fbtsm=new Fbtsm();
        fbtsm.setDate(getperviouscalender());
        fbtsm.setHour(getpervioushour());
        List<Fbtsm> list= fbtsmMapper.selectFbtsmList(fbtsm);
        for (Fbtsm b :list
        ) {
            int i=wsFbtsmMapper.insertFbtsm(b);
            if (i>0){
                System.out.println("武广Fbtsm插入成功");
            }
        }
    }

    @Scheduled(cron = "0 */20 * * * ?")
    public void insertgprs() {
        Gprs gprs=new Gprs();
        gprs.setDate(getperviouscalender());
        gprs.setHour(getpervioushour());
//        gprs.setDate("2023-11-18");
//        gprs.setHour(getpervioushour());
        List<Gprs> list= gprsMapper.selectGprsList(gprs);
        for (Gprs b :list
        ) {
            int i=wsGprsMapper.insertGprs(b);
            if (i>0){
                System.out.println("武广gprs插入成功");
            }
        }
    }

    @Scheduled(cron = "0 */30 * * * ?")
    public void inserttrx() {
        Trx trx=new Trx();
        trx.setDate(getperviouscalender());
        trx.setHour(getpervioushour());
        List<Trx> list= trxMapper.selectTrxList(trx);
        for (Trx b :list
        ) {
            int i=wsTrxMapper.insertTrx(b);
            if (i>0){
                System.out.println("武广trx插入成功");
            }
        }
    }
    @Scheduled(cron = "0 */30 * * * ?")
    public void insertdpc() {
        Dpc dpc=new Dpc();
        dpc.setDate(getperviouscalender());
        dpc.setHour(getpervioushour());
//        dpc.setDate("2023-11-18");
//        dpc.setHour(getpervioushour());
        List<Dpc> list= wgDpcMapper.selectDpcList(dpc);
        for (Dpc b :list
        ) {
            int i=wsDpcMapper.insertDpc(b);
            if (i>0){
                System.out.println("武广dpc插入成功");
            }
        }
    }



    //获取当前时间前一小时年月日yyyy-MM-dd格式
    public static String getperviouscalender(){
        Date now = new Date();

// 获取前一个小时的时间
        Calendar calendar = Calendar.getInstance();

        calendar.setTime(now);

        calendar.add(Calendar.HOUR_OF_DAY, -2);

        Date previousHour = calendar.getTime();
// 定义日期时间格式
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

        System.out.println("Current Time: " + formatter.format(now));

        System.out.println("Previous Hour: " + formatter.format(previousHour));
        return formatter.format(previousHour);
    }

    //获取当前时间前一小时年月日yyyy-MM-dd格式
    public static Long getpervioushour(){
        Date now = new Date();

// 获取前一个小时的时间

        Calendar calendar = Calendar.getInstance();

        calendar.setTime(now);

        calendar.add(Calendar.HOUR_OF_DAY, -2);
        long pervioushour= Long.parseLong(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY)));
        return pervioushour;
    }
}
